//
//  CCTabBarController.m
//  Baisibudejie
//
//  Created by yu hu on 2017/3/20.
//  Copyright © 2017年 yu hu. All rights reserved.
//

#import "CCTabBarController.h"
#import "FriendTrendViewController.h"
#import "EssenceViewController.h"
#import "NewViewController.h"
#import "MeViewController.h"
#import "CCTabBar.h"
#import "CCNavigationController.h"


@interface CCTabBarController ()

@end

@implementation CCTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    dict[NSForegroundColorAttributeName] = [UIColor grayColor];
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    selectedAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    [[UITabBarItem appearance]setTitleTextAttributes:dict forState:UIControlStateNormal];
    [[UITabBarItem appearance]setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    
    ;
    // 添加子控制器
    [self setUiWithVc:[[EssenceViewController alloc] init] title:@"精华" image:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon"];
    
    [self setUiWithVc:[[NewViewController alloc] init] title:@"新帖" image:@"tabBar_new_icon" selectedImage:@"tabBar_new_click_icon"];
    
    [self setUiWithVc:[[FriendTrendViewController alloc] init] title:@"关注" image:@"tabBar_friendTrends_icon" selectedImage:@"tabBar_friendTrends_click_icon"];
    
    [self setUiWithVc:[[MeViewController alloc] init] title:@"我" image:@"tabBar_me_icon" selectedImage:@"tabBar_new_click_icon"];
    
    [self setValue:[[CCTabBar alloc] init] forKey:@"tabBar"];
    
}

- (void)setUiWithVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
    
//    vc.view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(100)/100.0 green:arc4random_uniform(100)/100.0 blue:arc4random_uniform(100)/100.0 alpha:1.0];
    
    CCNavigationController *navc = [[CCNavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:navc];
    
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
}

@end
